package com.itheima.treeset.demo2;

import java.util.Collections;
import java.util.Comparator;
import java.util.TreeSet;

public class Demo2 {
    public static void main(String[] args) {
        TreeSet<Teacher> set = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int result = o1.getAge() - o2.getAge();
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        Teacher t1=new Teacher("zhangsan",23);
        Teacher t2=new Teacher("lisi",22);
        Teacher t3=new Teacher("wangwu",25);
        Collections.addAll(set,t1,t2,t3);
        for (Teacher teacher : set) {
            System.out.println(teacher);
        }

    }
}
